define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user/index',
                    add_url: 'user/user/add',
                    // edit_url: 'user/user/edit',
                    del_url: 'user/user/del',
                    multi_url: 'user/user/multi',
                    table: 'user',
                }
            });
            console.log(Config.levelConfig)
            console.log({ normal: __('Normal'), hidden: __('Hidden') })
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id'), sortable: true },
                        { field: 'level', title: __('身份'), searchList: Config.levelConfig, formatter: Table.api.formatter.label },
                        { field: 'nickname', title: __('Nickname'), operate: 'LIKE' },
                        { field: 'mobile', title: __('Mobile'), operate: 'LIKE' },
                        { field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false },
                        { field: 'money', title: __('Money'), operate: false, sortable: true },
                        { field: 'score', title: __('Score'), operate: false, sortable: true },
                        { field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: { normal: __('Normal'), hidden: __('Hidden') } },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'levelconfig',
                                    title: '升级',
                                    text: '升级',
                                    extend: 'data-area=["60%","60%"]',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'user/user/upgrades',//接口地址 控制器名/方法名
                                    visible: function(row){
                                        if (row.level > 0) {
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'clear',
                                    title: '清除等级',
                                    text: '清除等级',
                                    extend: 'data-area=["60%","60%"]',
                                    classname: 'btn btn-primary btn-xs btn-view btn-ajax',
                                    confirm:"是否确认清楚会员等级?",
                                    url: 'user/user/clear',//接口地址 控制器名/方法名
                                    visible: function(row){
                                        if (row.level > 0) {
                                            return true;
                                        }
                                    }
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        upgrades: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});